import { ReactNode } from 'react'
import { Redirect } from 'umi'
import { useSelector } from 'dva'
import { message } from 'antd'
interface Iprops {
  children?: ReactNode
}
export default function Auth(props: Iprops) {
  const courseInfo = useSelector((state: any) => state.saveInfo)
  console.log(courseInfo)
  const Authorization = localStorage.token
  if (!Authorization) {
    // 没有token就重定向
    return <Redirect to="/user/login" />
  } else if (courseInfo.courseId == undefined) {
    message.warning('请先选择要查看的班级！')
    return <Redirect to="/courseManagement" />
  } else {
    return <div>{props?.children}</div>
  }
}
